package com.qf.qfssm.web.master.utils;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.digest.DigestUtil;
import com.qf.qfssm.web.master.entity.Customer;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * @author 刘欣
 * @createTime 2023/1/11 16:29
 * @description
 */
public class RanDomeUserUntils {
    public static Customer getCustomer() throws ParseException {
        Customer customer = new Customer();
        customer.setName(getCustomerName());
        customer.setPassword(DigestUtil.md5Hex(getCustomerPassword()));
        customer.setSex(String.valueOf(getCustomerSex()));
        customer.setDate(randomTime());
        customer.setRegistTime(randomTime());
        return customer;
    }

    public static String getCustomerName() {
        return RandomUtil.randomString(5);
    }

    public static String getCustomerPassword() {
        return RandomUtil.randomString(6);
    }

    public static Integer getCustomerSex() {
        return Integer.parseInt(RandomUtil.randomString("10", 1));
    }

    public static Date randomTime() throws ParseException {
        Random rndYear = new Random();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        int year = rndYear.nextInt(18) + 2000;  //生成[2000,2017]的整数；年
        Random rndMonth = new Random();
        int month = rndMonth.nextInt(12) + 1;   //生成[1,12]的整数；月
        Random rndDay = new Random();
        int Day = rndDay.nextInt(30) + 1;       //生成[1,30)的整数；日
        Random rndHour = new Random();
        int hour = rndHour.nextInt(23);       //生成[0,23)的整数；小时
        Random rndMinute = new Random();
        int minute = rndMinute.nextInt(60);   //生成分钟
        Random rndSecond = new Random();
        int second = rndSecond.nextInt(60);    //生成秒
        return simpleDateFormat.parse(year + "-" + month + "-" + Day + " " + hour + ":" + minute + ":" + second);
    }

    public static List<Customer> getRandomCustomer(Integer num) throws ParseException {
        List<Customer> customers = new ArrayList<>();
        for (Integer i = 0; i < num; i++) {
            customers.add(getCustomer());
        }
        return customers;
    }


}
